/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import jeeobserver.HttpSessionObserver;
import jeeobserver.server.settings.Condition.TextCondition;
import jeeobserver.server.settings.Condition.TimePeriodCondition;

/**
 * The Class HttpSessionExclusionRule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public class HttpSessionExclusionRule extends Rule {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The project condition. */
	 private TextCondition projectCondition;

	 /** The session id condition. */
	 private TextCondition sessionIdCondition;

	 /** The duration condition. */
	 private TimePeriodCondition durationCondition;

	 public boolean isObserverInRule(HttpSessionObserver observer) {

			if (super.isObserverInRule(observer)) {

				 if ((this.projectCondition == null) || this.projectCondition.checkValue(observer.getProject())) {
						if ((this.sessionIdCondition == null) || this.sessionIdCondition.checkValue(observer.getProject())) {
							 if ((this.durationCondition == null) || (observer.isClosed() && this.durationCondition.checkNanosValue(observer.getTimeNanos()))) {
									return true;
							 }
						}
				 }
			}
			return false;
	 }

	 /**
	  * Gets the project condition.
	  *
	  * @return the project condition
	  */
	 public TextCondition getProjectCondition() {
			return this.projectCondition;
	 }

	 /**
	  * Sets the project condition.
	  *
	  * @param projectCondition the new project condition
	  */
	 public void setProjectCondition(TextCondition projectCondition) {
			this.projectCondition = projectCondition;
	 }

	 /**
	  * Gets the duration condition.
	  *
	  * @return the duration condition
	  */
	 public TimePeriodCondition getDurationCondition() {
			return this.durationCondition;
	 }

	 /**
	  * Sets the duration condition.
	  *
	  * @param durationCondition the new duration condition
	  */
	 public void setDurationCondition(TimePeriodCondition durationCondition) {
			this.durationCondition = durationCondition;
	 }

	 /**
	  * Gets the session id condition.
	  *
	  * @return the session id condition
	  */
	 public TextCondition getSessionIdCondition() {
			return this.sessionIdCondition;
	 }

	 /**
	  * Sets the session id condition.
	  *
	  * @param sessionIdCondition the new session id condition
	  */
	 public void setSessionIdCondition(TextCondition sessionIdCondition) {
			this.sessionIdCondition = sessionIdCondition;
	 }
}
